#include "sComponentObject.h"
#include "sObjectCreator.h"
#include "sGUI.h"

namespace sgui
{
namespace res
{
    sLinkTo<sComponent>& sComponentObject::getComponent()
    {
        return m_component;
    }

    const sLinkTo<sComponent>& sComponentObject::getComponent() const
    {
        return m_component;
    }
	
	inst::sComponentInstance* sComponentObject::getInstance(sGUI& gui, inst::sComponentInstance* parent)
	{
		sComponent* cmp = m_component.get();
		if (cmp)
		{
			return cmp->getInstance(gui, *this, parent);
		}
		return NULL;
	}

	CONTAINER_WRAPPER(sComponentObject)& sComponentObject::getChild()
	{
		return m_child;
	}

	const CONTAINER_WRAPPER(sComponentObject)& sComponentObject::getChild() const
	{
		return m_child;
	}

    void sComponentObject::load(db::Record &file)
    {
        sNamedObject::load(file);
        m_child.load(file[L"child"], fabric::fbObjectFabric);
		m_rect.load(file[L"rect"]);
    }

    void sComponentObject::save(db::Record &file) const
    {
        sNamedObject::save(file);
        file.Set(getClass());
        m_child.save(file[L"child"]);
		m_rect.save(file[L"rect"]);
    }

    void sComponentObject::clear()
    {
        m_child.clear();
        m_rect.clear();
    }

#ifdef _EDITOR
	void sComponentObject::exportRTTI(rtti::sInfoList& list)
    {
		REGISTER_RTTI(L"Rectangle", TEXT, NEW_RTTI_CLASS_PARAMETER(m_rect));
    }
#endif
	
	sComponentObject::sComponentObject(sGUI& gui, const std::wstring& name) :
		sNamedObject(gui, name),
        m_child(gui),
        m_component(gui)
    {

    }
};
};